package com.itfreer.special.report;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.DictionaryServiceImp;
import com.itfreer.form.api.dictionary.DictionaryEntity;

import java.util.HashMap;

/**
 * 定义报表实现类
 */
@Component
@Service(interfaceClass = SpecialReportService.class, path = "specialreport")
public class SpecialReportServiceImp extends DictionaryServiceImp<SpecialReportEntity> implements SpecialReportService {

	@Autowired
	private SpecialReportDao dao;

	@Override
	protected BaseDao<SpecialReportEntity> getDao() {
		return dao;
	}

	/**
	 * 是否是树表
	 */
	protected boolean isTree() {
		return true;
	}

	/**
	 * 树的PID字段名
	 */
	protected String getTreePIDFieldName() {
		return "pid";
	}

	@Override
	public String getDictionaryName() {
		return "specialReportDic";
	}

	@Override
	protected DictionaryEntity convert(SpecialReportEntity entity) {
		DictionaryEntity toEntity = new DictionaryEntity();
		toEntity.setDisplay(entity.getName());
		toEntity.setCode(entity.getId());
		toEntity.setId(entity.getId());
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("reportDicId", entity.getTablename());
		toEntity.setOther(map);
		BeanUtils.copyProperties(entity, toEntity);
		return toEntity;
	}

	@Override
	protected String getDictionaryFields() {
		return "*";
	}

	@Override
	public String getDicIdById(String id) {
		SpecialReportEntity entity = dao.getEntity(id);
		System.out.println(entity);
		return entity.getTablename();
	}
}
